package com.lzx.mumianaicodegenerator.core.saver;

import com.lzx.mumianaicodegenerator.ai.model.enums.CodeGenTypeEnum;
import com.lzx.mumianaicodegenerator.ai.model.HtmlCodeResult;
import com.lzx.mumianaicodegenerator.ai.model.MultiFileCodeResult;
import com.lzx.mumianaicodegenerator.exception.BusinessException;
import com.lzx.mumianaicodegenerator.exception.ErrorCode;

import java.io.File;

public class CodeFileSaverExecutor {
    private static final HtmlCodeFileSaverTemplate htmlCodeFileSaverTemplate = new HtmlCodeFileSaverTemplate();
    public static final MultiFileCodeFileSaverTemplate multiFileCodeFileSaverTemplate = new MultiFileCodeFileSaverTemplate();
    public static File executeSaver(Object codeResult, CodeGenTypeEnum codeGenType,Long appId){
        return switch (codeGenType) {
            case HTML -> htmlCodeFileSaverTemplate.saveCode((HtmlCodeResult) codeResult, appId);
            case MULTI_FILE -> multiFileCodeFileSaverTemplate.saveCode((MultiFileCodeResult) codeResult,appId);
            default -> throw new BusinessException(ErrorCode.SYSTEM_ERROR, "不支持的代码类型" + codeGenType);
        };
    }
}
